{include file="public/toper" /}
<div class="x-nav">
    <span class="layui-breadcrumb">
        <a href="">运营中心管理</a>
        <a href="">首页轮播</a>
    </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">&#xe666;</i></a>
</div>
<div class="x-body">
    <xblock class="demoTable">
        <button class="layui-btn" onclick="x_admin_show('添加图片','{:url(\'Image/add\')}','600','600')"><i class="layui-icon"></i>添加</button>
    </xblock>
    <table class="layui-hide" id="test" lay-filter="test"></table>
</div>
<script type="text/html" id="image">
    <img src="{{d.img}}" class="thumb" thumb="{{ d.img }}"/>
</script>
<script type="text/html" id="statusTpl">
    <input type="checkbox" name="state" value="{{ d.state }}" lay-skin="switch" lay-filter="switchStatus" lay-text="正常|关闭" {{ d.state == 1 ? 'checked' : '' }} data-href="{:url('state')}?table=image&id={{ d.image_id }}">
</script>
<script type="text/html" id="action">
    <button class="layui-btn layui-btn layui-btn-xs"  onclick="x_admin_show('编辑图片','{:url(\'Image/edit\')}?id={{d.image_id}}','600','600')"><i class="layui-icon">&#xe642;</i>编辑</button>
    <button class="layui-btn-danger layui-btn layui-btn-xs del_btn" id="{{d.image_id}}" lay-event="del"><i class="layui-icon">&#xe640;</i>删除</button>
</script>
<script>
    layui.use(['table','util'], function(){
        var table = layui.table, $ = layui.jquery;
        var layer = layui.layer;
        var loading = layer.load(1, {shade: [0.1,'#fff'] });
        var tableIn = table.render({
            method: 'post',
            elem: '#test'
            ,url: "{:url('Image/index')}"
            ,id:'test'
            ,cols: [[
                {field:'Image_id', width:80, title: '序号',align: 'center',type:'numbers'}
                ,{title: '图片',width:150,templet: '#image',align: 'center'}
                ,{field:'position', width:200, title: '位置',align: 'center',templet: function(d){if(d.position==1){ return '首页轮播图';}else if(d.position==2){return '首页中间banner';}}}
                ,{field:'url', width:200, title: '地址/商品id',align: 'center',templet: function(d){if(d.type==0){ return '跳转商品';}else if(d.type==1){return '跳转地址';}else if(d.type==2){return '不跳转';}}}
                ,{width: 140,title: '状态', align: 'center',templet: '#statusTpl'}
                ,{width: 190,title: '操作', align: 'center', toolbar: '#action'}
            ]]
            ,page: false
            ,limit: 30
            ,limits:[30,60,90,120,150,180,210,240,270,300]
        });
        layer.close(loading);

        table.on('tool(test)', function(obj) {
            var data = obj.data;
            if(obj.event === 'del'){
                layer.confirm('您确定要删除【'+data.image_id+'】吗？',{btnAlign: 'c'}, function(index){
                    var loading = layer.load(1, {shade: [0.1,'#fff'] });
                    $.post("{:url('Image/del')}",{id:data.image_id},function(res){
                        layer.close(loading);
                        if(res.code==200){
                            layer.msg(res.msg,{time:1000,icon:1});
                            tableIn.reload(test)
                        }else{
                            layer.msg(res.msg,{time:1000,icon:2});
                        }
                    });
                    layer.close(index);
                });
            }
        });
    });
</script>
{include file="public/footer"/}